package com.piesat.quake.business.device.model.config.network;

import com.piesat.quake.business.device.model.ConfigurationUpdate;
import com.piesat.quake.business.device.model.NetworkData;
import com.piesat.quake.business.device.mqtt.anno.CharField;
import com.piesat.quake.business.device.mqtt.anno.ConvertField;
import com.piesat.quake.business.device.mqtt.convert.IpConvert;

/**
 * mqtt网络配置
 */
public class MqttConfig {
    //网络地址	Int	4B	相应通信形式的IPv4地址转换出来对应的整型值；
    @ConvertField(length = 4, convert = IpConvert.class)
    private String address;
    //网络端口	Unsigned Short	2B	相应通信形式的的IPv4端口号，范围0-65535；
    private short port;
    //通信用户名	Char	32B	相应通信形式的的用户名，最大不超过32个字节，若用户名长度小于32个字节，则空余的空间用字节0来补充；仅对 1  MQTT，2  FTP，3  日志传输 生效；
    @CharField(32)
    private String username;
    //通信密码	Char	128B	相应通信形式的密码，最大不超过128个字节，若密码长度小于128个字节，则空余的空间用字节0来补充；
    //仅对 1  MQTT，2  FTP，3  日志传输 生效；
    @CharField(128)
    private String password;

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public short getPort() {
        return port;
    }

    public void setPort(short port) {
        this.port = port;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString() {
        return "MqttConfig{" +
                "\r\naddress='" + address + '\'' +
                ",\r\n port=" + port +
                ",\r\n username='" + username + '\'' +
                ",\r\n password='" + password + '\'' +
                "\r\n}";
    }

    public NetworkData toNetWorkData() {
        NetworkData networkData = new NetworkData();
        networkData.setAddress(address);
        networkData.setPort(port);
        networkData.setUsername(username);
        networkData.setPassword(password);
        networkData.setType(ConfigurationUpdate.Network.MQTT);
        return networkData;
    }
}